﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using EmoneyWeiXinEntity;
using EmoneyWeiXinCommon;
namespace EmoneyWeiXinDAL
{
    public  class WeixinNewsModelDal
    {
        public static List<WeixinNewsModelEntity> getNewsModelList(int weixinid, int pindex, int psize, out int total)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@weixinid", weixinid),
            new SqlParameter("@pindex",pindex),
            new SqlParameter("@psize", psize),
            new SqlParameter("@total",0),
            };
            parameters[3].Direction = ParameterDirection.Output;
            List<WeixinNewsModelEntity> result = SQLHelper.GetProcedureDataByColumnsLst<WeixinNewsModelEntity>(Config.EmoneyWeiXin, "sp_WeixinNewsModel_Select", parameters);
            total = Convert.ToInt32(parameters[3].Value);
            return result;
        }
        public static List<WeixinNewsModelEntity> getNewsModelListByID(int id)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@id", id)
            };
            List<WeixinNewsModelEntity> result = SQLHelper.GetProcedureDataByColumnsLst<WeixinNewsModelEntity>(Config.EmoneyWeiXin, "sp_WeixinNewsModel_SelectByID", parameters);
            return result;
        }
        public static int UpdateNewsModel(WeixinNewsModelEntity obj)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                 new SqlParameter("@weixinid", obj.weixinid),
                 new SqlParameter("@id", obj.id),
                 new SqlParameter("@modelid", obj.modelid),
                 new SqlParameter("@title", obj.title),
                 new SqlParameter("@content", obj.content),
                 new SqlParameter("@isvalid", obj.isvalid),
                 new SqlParameter("@remark", obj.remark),
                 new SqlParameter("@creator", obj.creator),
            };
            int result = SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_WeixinNewsModel_Update", parameters);
            return result;
        }

        public static int DeleteNewsModel(int id)
        {
            SqlParameter[] parameters = new SqlParameter[] {  
            new SqlParameter("@id", id)};
            int result = SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_WeixinNewsModel_Delete", parameters);
            return result;
        }
    }
}
